package Proj_pack;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;



public class Maschen {
	private List<Mash> maschen;
	
	public Maschen (Graph g){
		HashMap<Integer , Mash> init= new HashMap<Integer, Mash>();
		
		for(Knoten k :g.getKnmap().values()){
			int id =k.getCapacity();
			Mash actMash;
			if(init.containsKey(id)){
				actMash =init.get(id);	
			}else{
				actMash =new Mash(id);
				init.put(id, actMash);
			}
			init.get(id).add(k);
			
		}
		maschen = new LinkedList<Mash>(init.values());	
	}
	
	public synchronized void add(Mash neu){
		maschen.add(neu);
	}
	
	public synchronized boolean containsMash(Mash m){
		return maschen.contains(m);
	}


	public synchronized LinkedList<Mash> getMaschen() {
		return new LinkedList<Mash>(maschen);
	}
	
	
	public synchronized String toString(){
		StringBuffer sb = new StringBuffer();
		for (Mash m : maschen){
		sb.append("\n"+" {{"+ m +"}} " );
		
		}
		return sb.toString();
	}
	
}
